#!/usr.bin/env bash
#填写需要部署的harbor内网地址
harbor_host="192.168.1.100"
harbor_port="10808"
hostname=$(grep $harbor_host /etc/hosts|awk '{print $2}')
insecureText="    \"insecure-registries\": [\"https://$harbor_host\"],"
noProxyText="      \"no_proxy\": \"$harbor_host\","

#yum list installed |grep yq

#if $? ne 0;then
#yum install yq -y
#fi

#判断docker是否添加了harbor域名信任
grep -q  "insecure-regisries" /etc/docker/daemon.json
if [ $? -ne 0 ];then
sed -i "2i\\$insecureText" "/etc/docker/daemon.json"
fi

#判断docker是否添加了harbor域名不走代理
grep -q "no_proxy" /etc/docker/daemon.json
if [ $? -ne 0 ];then
line=$(grep -n "proxies" /etc/docker/daemon.json |awk -F':' '{print $1}')
line=$((line + 1))
sed -i "${line}i\\${noProxyText}" /etc/docker/daemon.json
fi

